<?php
namespace Home\Controller;

use Utuo\DistributionShopForeground;
use My\Model\AgentModel;
use My\Model\WechatUserModel;

class DisShopDealerController extends DistributionShopForeground {
	
	/**
	 * 初始化
	 */
	public function _init() {
		layout('disshop');
		$this->setModelName("DistributionShop");
		$this->setModelControllerName("DisShop");
		if ( in_array(ACTION_NAME, array('apply', 'search')) ) { // 支持跳转获得用户信息
			$this->setSupportRedirect(isset($_REQUEST['debug'])?false:true);
		}
	}
	
	/**
	 * 申请金牌会员
	 */
	public function applyAction() {
		$name = WechatUserModel::getUserTypeName(WechatUserModel::USER_TYPE_FRANCHISED_DEALER, $this->cid, 0);
		$this->setPageTitle("{$name}在线申请");
		$this->display("{$this->modelControllerName}/dealerApply");
	}
		
	/**
	 * 提交申请
	 */
	public function applyPostAction() {
		$d = D("DealerApply");
		if ( $d->create() ) {
			$d->cid = $this->cid or $this->ajaxError('未知商家');
			$d->openId = $this->openId or $this->ajaxError('访问已超时请重新进入');
			if ( false !== $d->add() ) {
				$this->ajaxSuccess('您的申请已提交,我们会尽快与您联系');
			}
			$this->ajaxError('提交失败请重试');
		}
		$this->ajaxError($d->getError());
	}
	
}